﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcmyjobs.Web.users
{
    public partial class modify_basic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Title = string.Format("个人管理中心—我的简历：基本资料&bull;联系方式   {0}", Application["webname"].ToString());
                txthuji.Attributes.Add("readonly", "true");
                txtaddress.Attributes.Add("readonly", "true");
                if (Session["user_id"] != null)
                {
                    int id = int.Parse(Session["user_id"].ToString());
                    this.lblName.Text = Session["user_name"].ToString();
                    HyperLink1.NavigateUrl = "show_user-" + id + ".html";
                    HyperLink1.Target = "_blank";
                    show(id);
                }
                else
                {
                    Response.Redirect("userlogin.html");
                }
            }

        }
        protected void show(int id)
        {
            lcmyjobs.BLL.user_basic bll = new lcmyjobs.BLL.user_basic();
            DataSet ds = bll.GetUserBasic(id);

            if (ds != null && ds.Tables[0].Rows.Count != 0)
            {
                //[truename],[sex],[age],[height],[address],[huji],[email],[phone],[onlinecontact]
                this.txttruename.Text = ds.Tables[0].Rows[0][0].ToString();
                bool sex = bool.Parse(ds.Tables[0].Rows[0][1].ToString());
                if (!sex)
                    rbtWomen.Checked = true;
                else
                    rbtMan.Checked = true;
                this.txtage.Text = ds.Tables[0].Rows[0][2].ToString();
                this.txtheight.Text = ds.Tables[0].Rows[0][3].ToString();
                this.txtaddress.Text = ds.Tables[0].Rows[0][4].ToString();
                hfaddress.Value = this.txtaddress.Text;
                this.txthuji.Text = ds.Tables[0].Rows[0][5].ToString();
                hfhuji.Value = this.txthuji.Text;
                this.txtemail.Text = ds.Tables[0].Rows[0][6].ToString();
                hfemail.Value = this.txtemail.Text;
                this.txtphone.Text = ds.Tables[0].Rows[0][7].ToString();
                string[] online = ds.Tables[0].Rows[0][8].ToString().Split('：');
                if (online.Length == 2)
                {
                    if (online[0] == "QQ")
                        rbtQQ.Checked = true;

                    this.txtonlinecontact.Text = online[1];
                }


            }

        }

        protected void btnedu_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (Session["user_id"] != null)
                {

                    string truename = this.txttruename.Text;
                    bool sex;
                    if (rbtMan.Checked)
                        sex = true;
                    else
                        sex = false;
                    int age = int.Parse(this.txtage.Text);
                    int height = int.Parse(this.txtheight.Text);
                    string address = this.txtaddress.Text;
                    string huji = this.txthuji.Text;
                    string email = this.txtemail.Text;
                    string phone = this.txtphone.Text;
                    string onlinecontact = this.txtonlinecontact.Text;

                    lcmyjobs.Model.user_basic model = new lcmyjobs.Model.user_basic();
                    model.uid = int.Parse(Session["user_id"].ToString());
                    model.truename = truename;
                    model.sex = sex;
                    model.age = age;
                    model.height = height;
                    model.address = address;
                    model.huji = huji;
                    model.email = email;
                    model.phone = phone;
                    string line = "";
                    if (onlinecontact.Trim() != "")
                    {
                        if (rbtQQ.Checked)
                            line = "QQ：";

                        model.onlinecontact = line + onlinecontact;
                    }
                    lcmyjobs.BLL.user_basic bll = new lcmyjobs.BLL.user_basic();
                    int webid = int.Parse(Application["webid"].ToString());
                    int i = bll.Add(model, webid, 1);
                    if (i != 0)
                    {
                        Session["user_name"] = txttruename.Text.Trim() + "  " + (rbtMan.Checked ? "先生" : "女士");
                        this.lblName.Text = Session["user_name"].ToString();
                        Maticsoft.Common.MessageBox.Show(this, "修改成功！");
                        show(model.uid);
                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.Show(this, "注册失败！");
                    }
                }
            }
        }
    }
}